﻿using System;
using System.Collections.Generic;

namespace NiuX.Utils.DependencyInjection;

public class ServiceRegistry
{
    public Type ServiceType { get; set; }


    public LifetimeType LifetimeType { get; set; }

    public Func<ServiceContainer, Type[], object> Factory { get; set; }


    internal ServiceRegistry Next { get; set; }

    public ServiceRegistry(Type serviceType, LifetimeType lifetimeType, Func<ServiceContainer, Type[], object> factory)
    {
        ServiceType = serviceType;
        LifetimeType = lifetimeType;
        Factory = factory;
    }

    public IEnumerable<ServiceRegistry> AsEnumerable()
    {
        for (var self = this; self != null; self = self.Next)
        {
            yield return self;
        }
    }

    public List<ServiceRegistry> AsList()
    {
        var list = new List<ServiceRegistry>();
        for (var self = this; self != null; self = self.Next)
        {
            list.Add(self);
        }
        return list;
    }
}